package com.yn.front.zy;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yn.common.model.zy.TDeviceInfoDO;
import com.yn.common.page.BasePage;
import com.yn.common.request.sc.PageParamRequest;
import com.yn.common.response.sc.BaseResult;
import com.yn.service.zy.TDeviceInfoService;
import com.yn.service.zy.model.dto.TDeviceInfoDTO;
import com.yn.service.zy.model.query.TDeviceInfoQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/tdeviceinfo")
@Api(tags = "设备相关接口")
public class TDeviceInfoController {
    @Autowired
    private TDeviceInfoService tDeviceInfoService;

    /**
     * 分页获取设备信息
     * @param query
     * @param basePage
     * @return
     */
  /*  @GetMapping("/list-page")
    @ApiOperation("分页获取设备信息")
    public BaseResult listPage(TDeviceInfoQuery query, BasePage basePage){
        IPage<TDeviceInfoDTO> tDeviceInfoDTOIPage = tDeviceInfoService.listPage(query,basePage);

        return BaseResult.success(tDeviceInfoDTOIPage);
    }*/
    /**
     * 分页获取设备信息
     * @param query
     * @param pageRequest
     * @return
     */
    @GetMapping("/list-page")
    @ApiOperation("分页获取设备信息")
    public BaseResult<BasePage<TDeviceInfoDTO>> listPage1(TDeviceInfoQuery query, PageParamRequest pageRequest) {
        return BaseResult.success(tDeviceInfoService.listPage1(query, pageRequest));
    }

    /**
     * 获取设备详情
     * @param deviceId
     * @return
     */
    @GetMapping("/info")
    @ApiOperation("获取设备详情")
    public BaseResult<TDeviceInfoDTO> info(@RequestParam(value = "deviceId",required = true)
                           @NotNull(message = "请选择设备")
                           @ApiParam(value = "设备id",required = true) Integer deviceId){
        TDeviceInfoDO tDeviceInfoDO = tDeviceInfoService.getById(deviceId);

        TDeviceInfoDTO tDeviceInfoDTO = TDeviceInfoDTO.transform(tDeviceInfoDO);
        return BaseResult.success(tDeviceInfoDTO);
    }

}
